#ifndef __SCNS_SMCTP_EXT_OSCILLOSCOPE_H__
#define __SCNS_SMCTP_EXT_OSCILLOSCOPE_H__

#include "ScnsConfig.h"

#if defined(SCNS_SMCTP_EXT_OSCILLOSCOPE_ENABLE)&&SCNS_SMCTP_EXT_OSCILLOSCOPE_ENABLE==1

#include "ScnsYing.h"
#include "ScnsSmctp.h"
#include "ScnsBuffer.h"

extern void scnsSmctpExtOscilloscopeTest(ScnsSmctpChannelEnum ch,int n,uint8 type);
extern void __scnsSmctpExtOscilloscopeSendRaw(ScnsSmctpChannelEnum ch,const uint8*data,uint8 n,const char*name,uint8 ceilSize,uint8 type,int32 bias,uint32 block);


#define     scnsSmctpExtOscilloscopeSendFloat16(ch,block,...)        do{                                    \
        const float __data_tmp__[]={__VA_ARGS__};                                                           \
        uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*2];                                   \
        for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
        {scnsBufferSetFloat16(__data__,__data__i__*2,sizeof(__data__),__data_tmp__[__data__i__]);}          \
        __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,2,0X79,0,block); \
    }while(0)


#define     scnsSmctpExtOscilloscopeSendFloat24(ch,block,...)        do{                                    \
        const float __data_tmp__[]={__VA_ARGS__};                                                           \
        uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*3];                                   \
        for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
        {scnsBufferSetFloat24(__data__,__data__i__*3,sizeof(__data__),__data_tmp__[__data__i__]);}          \
        __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,3,0X7A,0,block); \
    }while(0)

#define     scnsSmctpExtOscilloscopeSendFloat(ch,block,...)        do{                                      \
        const float __data_tmp__[]={__VA_ARGS__};                                                           \
        uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*4];                                   \
        for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
        {scnsBufferSetFloat(__data__,__data__i__*4,sizeof(__data__),__data_tmp__[__data__i__]);}            \
        __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,4,0X7F,0,block); \
    }while(0)

#define     scnsSmctpExtOscilloscopeSendInt16(ch,block,...)        do{                                      \
        const int32 __data_tmp__[]={__VA_ARGS__};                                                           \
        uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*2];                                   \
        for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
        {scnsBufferSetInt16(__data__,__data__i__*2,sizeof(__data__),scnsLimit2(__data_tmp__[__data__i__],INT16_MIN,INT16_MAX));}   \
        __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,2,0X7C,0,block); \
    }while(0)

#define     scnsSmctpExtOscilloscopeSendInt32(ch,block,...)        do{                                      \
        const int32 __data_tmp__[]={__VA_ARGS__};                                                           \
        uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*4];                                   \
        for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
        {scnsBufferSetInt32(__data__,__data__i__*4,sizeof(__data__),__data_tmp__[__data__i__]);}            \
        __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,4,0X7B,0,block); \
    }while(0)

#define     scnsSmctpExtOscilloscopeSendIntAuto(ch,block,...)   do{                                             \
        int32 __data_tmp__[]={__VA_ARGS__};                                                                     \
        int32 __data__min__=__data_tmp__[0];                                                                    \
        int32 __data__max__=__data_tmp__[0];                                                                    \
        for(uint8 __data__i__=1;__data__i__<sizeof(__data_tmp__)/sizeof(__data_tmp__[0]);++__data__i__)         \
        {                                                                                                       \
            __data__min__=scnsMin(__data__min__,__data_tmp__[__data__i__]);                                     \
            __data__max__=scnsMax(__data__max__,__data_tmp__[__data__i__]);                                     \
        }                                                                                                       \
        if(INT16_MIN<=__data__min__&&__data__max__<=INT16_MAX)                                                  \
        {                                                                                                       \
            uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*2];                                   \
            for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
            {scnsBufferSetInt16(__data__,__data__i__*2,sizeof(__data__),__data_tmp__[__data__i__]);}            \
            __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,2,0X7C,0,block); \
        }                                                                                                       \
        else if((__data__max__-__data__min__)<=UINT16_MAX)                                                      \
        {                                                                                                       \
            uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*2];                                   \
            for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
            {scnsBufferSetUint16(__data__,__data__i__*2,sizeof(__data__),__data_tmp__[__data__i__]-__data__min__);}            \
            __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,2,0X7E,__data__min__,block); \
        }                                                                                                       \
        else                                                                                                    \
        {                                                                                                       \
            uint8 __data__[(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]))*4];                                   \
            for(uint8 __data__i__=0;__data__i__<(sizeof(__data_tmp__)/sizeof(__data_tmp__[0]));++__data__i__)   \
            {scnsBufferSetInt32(__data__,__data__i__*4,sizeof(__data__),__data_tmp__[__data__i__]);}            \
            __scnsSmctpExtOscilloscopeSendRaw(ch,__data__,(sizeof(__data_tmp__)/sizeof(__data_tmp__[0])),#__VA_ARGS__,4,0X7B,0,block); \
        }                                                                                                       \
    }while(0)

#endif
#endif
